package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.regulatorDevice_maintenanceCard.RegulatorDevice_MaintenanceCardGetModel;
import com.hzhr.iot.device.model.regulatorDevice_maintenanceCard.RegulatorDevice_MaintenanceCardPostModel;
import com.hzhr.iot.device.service.RegulatorDevice_MaintenanceCardService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "RegulatorDevice_MaintenanceCard", description = "调压设备的维护卡片")
@RestController
@RequestMapping(value = "")
public class RegulatorDevice_MaintenanceCardController extends BaseController {

    @Autowired
    RegulatorDevice_MaintenanceCardService regulatorDevice_maintenanceCardService;


    //region /regulator-devices/{regulatorDeviceId}/maintenance-cards POST
    //region swagger响应码 : postByRegulatorDeviceId
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证调压设备的存在性  \n----异常说明 : 调压设备不存在  \n\n----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证卡片的存在性  \n----异常说明 : 本年度的维护卡已存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : postByRegulatorDeviceId
    @ApiOperation(value="根据调压设备编号创建调压设备的维护卡片", notes="根据调压设备编号创建调压设备的维护卡片  \n简介 : 根据调压设备编号创建调压设备的维护卡片  \n步骤 :  \n1. 验证调压设备的存在性 :  \n 根据路径参数regulatorDeviceId查询采集设备(COLLECT_DEVICE)对象collectDevice_1，  \n 路径参数筛选规则如下：  \n (1) collectDevice_1.id = 路径参数regulatorDeviceId;  \n 额外筛选规则如下：  \n (1) collectDevice_1.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；  \n 如果collectDevice_1不存在，抛出异常201  \n2. 验证卡片的存在性 :  \n 根据body.year和路径参数regulatorBoxId查询设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_1，  \n 筛选规则如下：  \n (1) deviceMaintenance.id = 路径参数regulatorDeviceId；  \n (2) deviceMaintenance.year = body.year；  \n 如果deviceMaintenance_1存在，抛出异常202，  \n3. 新增信息卡片 :  \n 根据body创建设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_2；  \n4. 返回信息 :  \n创建对象  \n 根据条件参数查询修改后的对象deviceMaintenance_2的信息生成结果对象并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : postByRegulatorDeviceId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),


    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : postByRegulatorDeviceId
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/maintenance-cards", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<RegulatorDevice_MaintenanceCardGetModel> postByRegulatorDeviceId(@PathVariable("regulatorDeviceId") Integer regulatorDeviceId,
                                                                                           @RequestParam @ApiIgnore Map<String, Object> query,
                                                                                           @RequestBody RegulatorDevice_MaintenanceCardPostModel body) throws ServiceException {
        RegulatorDevice_MaintenanceCardGetModel responseBody = regulatorDevice_maintenanceCardService.postByRegulatorDeviceId(initHeader(), regulatorDeviceId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /regulator-devices/{regulatorDeviceId}/maintenance-cards GET
    //region swagger响应码 : getByRegulatorDeviceId
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : getByRegulatorDeviceId
    @ApiOperation(value="根据调压设备编号查询调压设备的维护卡片", notes="根据调压设备编号查询调压设备的维护卡片  \n简介 : 根据调压设备编号查询调压设备的维护卡片  \n步骤 :  \n1. 查询维护卡片 :  \n 根据条件参数和路径参数regulatorDeviceId查询DEVICE_MAINTENANCE_CARD对象集合deviceMaintenanceList_1，  \n 路径参数的筛选规则如下：  \n (1) deviceMaintenanceList_1[i].deviceId = 路径参数regulatorDeviceId；  \n 额外的筛选条件如下：  \n (2) deviceMaintenanceList_1[i]..deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；  \n2. 返回信息 :  \n 根据deviceMaintenanceList_1及条件参数生成结果对象并返回;  \n",produces = "application/json")
    //endregion
    //region swagger参数 : getByRegulatorDeviceId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_year", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.year = #{equal_year}",required = false, dataType = "string", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_year", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.year = #{_equal_year}",required = false, dataType = "string", paramType = "query"),

    })
    //endregion
    //region 请求 : getByRegulatorDeviceId
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/maintenance-cards", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<RegulatorDevice_MaintenanceCardGetModel> getByRegulatorDeviceId(@PathVariable("regulatorDeviceId") Integer regulatorDeviceId,
                                                             @RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        RegulatorDevice_MaintenanceCardGetModel responseBody = regulatorDevice_maintenanceCardService.getByRegulatorDeviceId(initHeader(), regulatorDeviceId, query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}


































































































































































